package com.example.farmer.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.farmer.R;

public class PosterPublishActivity extends AppCompatActivity {

    private Spinner spPosterCategory;
    private EditText etPosterPrice, etPosterAddress;
    private Button btnPublish;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_poster_publish);

        spPosterCategory = findViewById(R.id.spPosterCategory);
        etPosterPrice = findViewById(R.id.etPosterPrice);
        etPosterAddress = findViewById(R.id.etPosterAddress);
        btnPublish = findViewById(R.id.btnPublish);

        // 设置海报分类的 Spinner
        ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter.createFromResource(this,
                R.array.poster_categories, android.R.layout.simple_spinner_item);
        categoryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spPosterCategory.setAdapter(categoryAdapter);

        // 设置发布按钮的点击事件
        btnPublish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                publishPoster();
            }
        });
    }

    private void publishPoster() {
        String category = spPosterCategory.getSelectedItem().toString();
        String price = etPosterPrice.getText().toString();
        String address = etPosterAddress.getText().toString();

        // 在这里添加发布海报的逻辑，例如将数据提交到服务器或本地存储

        // 简单示例：显示发布信息
        String message = "发布海报:\n" +
                "分类: " + category + "\n" +
                "单价: " + price + "\n" +
                "地址: " + address;
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }
}
